
import { useEffect, useState, useRef } from 'react';


const useDebounced = (cb: Function, time: number = 3000) => {

    const timeoutRef = useRef<null | NodeJS.Timeout>(null); // 用于保存定时器引用

    const fun = (value) => {
        if (timeoutRef.current) {
            clearTimeout(timeoutRef.current);
        }

        timeoutRef.current = setTimeout(() => {
            cb(value);
        }, time); // 3秒后调用API
    }

    return fun
}

export default useDebounced